﻿@page "/test"
@using BXJG.Common
@using BXJG.Common.Events
@using BXJG.Common.Http
@using Microsoft.AspNetCore.Components.Authorization

@attribute [Authorize("Administrator")]
@inject AuthenticationStateProvider authSP
@attribute [ReuseTabsPage(Title = "测试")]
@implements IDisposable
@inherits BaseComponent
<PageTitle>测试1111111</PageTitle>
<p>
    @count
</p>
<Button OnClick="ccc">
    测试
</Button>
accessToken：
@kkk
<br />
<br />
这个页面是auto模式(早期以server模式，后期以client模式运行)
<br />
同时登陆后才能看到，为了测试身份验证。
<br />
F12查看浏览器日志，以确定它是否在浏览器种执行
<br />

<Button OnClick="sjzxcs">
    基于事件的跨组件通信测试
</Button>
<Button OnClick="qjyccs">
   全局异常aop测试
</Button>

<AuthorizeView Policy="Administrator">
    鉴权Administrator成功！
</AuthorizeView>
<br />


@code {
    // IDisposable sj;
    //  Zhongjie zhongjie;
    [Inject]
    private Zhongjie sdfsdf{ get; }
    public void Dispose()
    {
       // sj?.Dispose();
    }
    string kkk = string.Empty;
    int count;
   
    async Task ccc()
    {
       // Console.WriteLine(DateTime.Now.ToLongTimeString());
        var sdfsd = await authSP.GetAuthenticationStateAsync();
        kkk = sdfsd.User.Claims.SingleOrDefault(c => c.Type == "AccessToken")?.Value;
        count++;
    }
    async Task sjzxcs()
    {
        await sdfsdf.Chufa("aaa");
    }
    [AbpExceptionInterceptor]
    void qjyccs()
    {
        throw new UserFriendlyException("若看到此消息，说明全局异常拦截执行成功！");
    }

    protected override void OnInitialized()
    {
        // var sdfsdf = base.ScopedServices.GetRequiredService<IZhongjieProvider>();
        //    zhongjie = sdfsdf.GetCurrent();
        //    if(zhongjie!=default)
        // {   sj = zhongjie.Zhuce(() =>
        //    {
        //        Console.WriteLine("事件触发了");
        //        return ValueTask.CompletedTask;
        //    }, "aaa");
    }
}